#ifndef __RPC_SERVER_H__
#define __RPC_SERVER_H__

#include "ret.h"
#include "transmission.h"
#include "message.h"

#include <pthread.h>

extern char g_server_run_flag;

#define EXECUTE_THREAD_NUM (4)

typedef struct {
    size_t tasks_max_size;
    size_t products_max_size;
    transmission_type_t transmission_type;
    transmission_server_config_t transmission_config;
}server_config_t;

typedef struct _thread_t{
    pthread_cond_t cond;
    pthread_mutex_t mutex;
    pthread_t worker;
    message_queue_t* tasks;
}worker_info_t;

worker_info_t* worker_create(const server_config_t*);
void worker_destroy(worker_info_t*);

typedef struct {
    server_config_t* config;
    pthread_t main;
    worker_info_t* workers_info[EXECUTE_THREAD_NUM];
    message_queue_t* products;
    transmission_server_t* transport;
}rpc_server_t;

/**
 * @brief 创建server并初始化
 * 
 * @param config server配置
 * @return rpc_server_t* 
 */
rpc_server_t*
rpc_server_create(server_config_t* config);

ret_t rpc_server_start(rpc_server_t* server);

ret_t rpc_server_destroy(rpc_server_t** server);



#endif // __RPC_SERVER_H__